package com.prs.crm.domain.oa;

import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.prs.crm.domain.BaseEntity;
import com.prs.crm.domain.doc.Document;
import com.prs.crm.domain.hr.Person;
@Entity
@Table(name="oa_task")
public class OaTask extends BaseEntity{
	
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	private String title;
	@ManyToOne
	private OaTaskType type;
	@ManyToOne
	private OaTaskSource source;
	@Lob
	private String content;
	private String attach;
	@ManyToOne
	private OaTask upTask;
	private Date beginTime;
	private Date endTime;
	private String state;
	private String level;
	@OneToMany(fetch=FetchType.LAZY,mappedBy="upTask")
	@OrderBy
	private Set<OaTask> tasks;
	@ManyToMany(fetch=FetchType.LAZY)
	private Set<Person> copyToPersons;
	@OneToMany(fetch=FetchType.LAZY,mappedBy="task")
	private Set<OaTaskSubmit> submits;
	@OneToMany(fetch=FetchType.LAZY,mappedBy="task")
	private Set<OaTaskCritique> critiques;
	@OneToMany(fetch=FetchType.LAZY,mappedBy="oaTask")
	private Set<Document> docs;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public OaTaskType getType() {
		return type;
	}
	public void setType(OaTaskType type) {
		this.type = type;
	}
	public OaTaskSource getSource() {
		return source;
	}
	public void setSource(OaTaskSource source) {
		this.source = source;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getAttach() {
		return attach;
	}
	public void setAttach(String attach) {
		this.attach = attach;
	}
	public OaTask getUpTask() {
		return upTask;
	}
	public void setUpTask(OaTask upTask) {
		this.upTask = upTask;
	}
	public Date getBeginTime() {
		return beginTime;
	}
	public void setBeginTime(Date beginTime) {
		this.beginTime = beginTime;
	}
	public Date getEndTime() {
		return endTime;
	}
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	public void setTasks(Set<OaTask> tasks) {
		this.tasks = tasks;
	}
	public Set<OaTask> getTasks() {
		return tasks;
	}

	public void setLevel(String level) {
		this.level = level;
	}
	public String getLevel() {
		return level;
	}
	public void setSubmits(Set<OaTaskSubmit> submits) {
		this.submits = submits;
	}
	public Set<OaTaskSubmit> getSubmits() {
		return submits;
	}
	public void setCopyToPersons(Set<Person> copyToPersons) {
		this.copyToPersons = copyToPersons;
	}
	public Set<Person> getCopyToPersons() {
		return copyToPersons;
	}
	
	
	public void addCopyToPersons(Collection<Person> persons) {		
		if(persons != null) {
			if(copyToPersons == null) {
				copyToPersons = new HashSet<Person>();
			}
			copyToPersons.addAll(persons);
		}
	}
	
	public void addDocs(Document doc) {
		if(docs == null) {
			docs = new HashSet<Document>();
		}
		docs.add(doc);
	}
	public void setCritiques(Set<OaTaskCritique> critiques) {
		this.critiques = critiques;
	}
	public Set<OaTaskCritique> getCritiques() {
		return critiques;
	}
	public void setDocs(Set<Document> docs) {
		this.docs = docs;
	}
	public Set<Document> getDocs() {
		return docs;
	}
}